<template>
  <div>
      <h1>权限页面</h1>
      当前用户权限：
      <ul>
          <li v-for="user_p in user_permission_list" :key="user_p.id">{{user_p[1]}}</li>
      </ul>
      所有权限:
      <ul>
          <li v-for="p in permission_list" :key="p.id">{{p[1]}}</li>
      </ul>
      用户添加未拥有权限：
      <ul>
          <li v-for="p in permission_list" :key="p.id">{{p[1]}}
              <input type="button" @click="addpermission(p[0])" value="添加权限">
          </li>
      </ul>
  </div>
</template>

<script>
export default {
    data(){
        return{
            username:localStorage.getItem('username'),
            token:localStorage.getItem('jwt'),
            user_permission_list:[],
            permission_list:[],
            permission:''
        }
    },
    created(){
        this.axios.get('http://127.0.0.1:8000/get_user_access?token='+this.token).then(resp=>{
            console.log(resp.data[1][1])
            this.user_permission_list = resp.data
        }).catch(error=>{
            console.log(error)
        }),
        this.axios.get('http://127.0.0.1:8000/permission_list').then(resp=>{
            console.log(resp.data)
            this.permission_list = resp.data
        }).catch(error=>{
            console.log(error)
        })
    },
    methods:{
        addpermission(pid){
            let data = new FormData
            data.append('token',this.token)
            data.append('pid',pid)
            this.axios.post('http://127.0.0.1:8000/add_permission',data).then(resp=>{
                console.log(resp.data)
            }).catch(error=>{
                console.log(error)
            })
        }
    }
}
</script>

<style>

</style>